package com.haipumi.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.haipumi.beans.IndexTaskData;
import com.haipumi.beans.haipumi_reply;
import com.haipumi.beans.haipumi_task;
import com.haipumi.beans.haipumi_user;
import com.haipumi.dao.TaskDao;

@Repository("taskDaoMybatisImpl")
public class TaskDaoMybatisImpl implements TaskDao{

	private SqlSessionTemplate session;
	
	@Resource(name="sqlSession")
	public void setSession(SqlSessionTemplate session) {
		this.session = session;
	}

	@Override
	public List<IndexTaskData> SelectIndexTask(haipumi_task task) {
		return session.selectList("com.haipumi.dao.taskMapper.SelectIndexTask", task);
	}

	@Override
	public boolean addTask(haipumi_task task) {
		 int flag=session.insert("com.haipumi.dao.taskMapper.InsertTask", task);
		 if(flag>0){
			 return true;
		 }
		 return false;
	}

	@Override
	public List<haipumi_task> findAllTask(String uid,String status) {
		Map paramMap=new HashMap();
		paramMap.put("uid",uid);
		paramMap.put("status",status);
		return session.selectList("com.haipumi.dao.taskMapper.findAllTask",paramMap);
	}

	@Override
	public List<haipumi_reply> findReply(String tid) {
		Map paramMap=new HashMap();
		paramMap.put("tid",tid);
		return session.selectList("com.haipumi.dao.taskMapper.findReply",paramMap);
	}

	@Override
	public boolean addReply(haipumi_reply reply) {
		int flag=session.insert("com.haipumi.dao.taskMapper.addReply", reply);
		if(flag>0){
			return true;
		}
		return false;
	}

	@Override
	public int acceptTask(haipumi_user user, String tid) {
		Map paramMap=new HashMap();
		paramMap.put("tid",tid);
		paramMap.put("uid", user.getUid());
		
		int flag=session.update("com.haipumi.dao.taskMapper.acceptTask", paramMap);
		return flag;
	}

	@Override
	public List<haipumi_task> findCareList(String uid, String tid) {
		Map paramMap=new HashMap();
		paramMap.put("tid",tid);
		paramMap.put("uid", uid);
		
		return session.selectList("com.haipumi.dao.taskMapper.findCareList",paramMap);
	}

	@Override
	public boolean updateCareList(String tider, String tid) {
		Map paramMap=new HashMap();
		paramMap.put("tider",tider);
		paramMap.put("tid", tid);
		
		int flag=session.update("com.haipumi.dao.taskMapper.updateCareList",paramMap);
		if(flag>0){
			return true;
		}
		return false;
	}

	@Override
	public boolean updateUserLike(String ulike, String uid) {
		Map paramMap=new HashMap();
		paramMap.put("ulike",ulike);
		paramMap.put("uid", uid);
		
		int flag=session.update("com.haipumi.dao.taskMapper.updateUserLike",paramMap);
		if(flag>0){
			return true;
		}
		return false;
	}

	@Override
	public List<haipumi_task> findShieldList(String tid) {
		Map paramMap=new HashMap();
		paramMap.put("tid",tid);
		
		return session.selectList("com.haipumi.dao.taskMapper.findShieldList",paramMap);
	}

	@Override
	public int updateTaskShield(String tid, String tshield) {
		Map paramMap=new HashMap();
		paramMap.put("tid",tid);
		paramMap.put("tshield", tshield);
		
		return session.update("com.haipumi.dao.taskMapper.updateTaskShield",paramMap);
	}

	@Override
	public int operateTask(String status,String tid, String tider, String tshield) {
		Map paramMap=new HashMap();
		paramMap.put("status",status);
		paramMap.put("tid",tid);
		paramMap.put("tider",tider);
		paramMap.put("tshield", tshield);
		
		return session.update("com.haipumi.dao.taskMapper.operateTask",paramMap);
	}
	

}
